import cv2
import time
import all_socket
import struct


def camera_send():
  cap = cv2.VideoCapture(8)
  while True:
    ret, frame = cap.read()
    _, img_encoded = cv2.imencode('.jpg', frame)
    img_bytes = img_encoded.tobytes()
    all_socket.camera_socket.sendall(struct.pack(">L", len(img_bytes)))
    all_socket.camera_socket.sendall(img_bytes)
    time.sleep(0.05)
  cap.release()
  all_socket.camera_socket.close()


